﻿using LiteFramework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace Website.Action
{
    public class AceModel_Role : IAceModel
    {
        private LiteFramework.Model.Role _source = null;
        public AceModel_Role(LiteFramework.Model.Role source)
        {
            BaseFramework.DataValid.IsNull(source, "source");

            //this.id = role.Id;
            //this.name = role.Name;
            //this.timecreated = role.TimeCreated;
            //this.description = role.Description;

            this._source = source;
        }

        public string id { get; set; }
        public string name { get; set; }
        public bool isSystem { get; set; }
        public bool active { get; set; }
        public DateTime timecreated { get; set; }
        public string description { get; set; }

        public string ToJsonString()
        {
            return new Json()
                    .Add("id", this._source.Id)
                    .Add("name", this._source.Name)
                    .Add("timecreated", this._source.TimeCreated, "yyyy-MM-dd")
                    .Add("issystem", this._source.IsSystem)
                    .Add("description", this._source.Description)
                    .ToJsonString();
        }

        public static IEnumerable<AceModel_Role> ParseList(IEnumerable<LiteFramework.Model.Role> sources)
        {
            if (sources == null || sources.Count() == 0) throw new ArgumentException("至少包含一项", "sources");
            foreach (var item in sources)
            {
                yield return new AceModel_Role(item);
            }
        }
    }
}